package com.blockmeta.bbs.businesslibrary.dialog;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;

import androidx.appcompat.app.AlertDialog;

import com.blockmeta.bbs.baselibrary.net.callback.SuccessCallBack;
import com.blockmeta.bbs.baselibrary.utils.NetworkStateUtil;
import com.blockmeta.bbs.baselibrary.utils.SharedPreferenceUtil;
import com.blockmeta.bbs.baselibrary.utils.permission.RequestPermissionUtil;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.businesslibrary.util.DeviceUtil;

/**
 * Created by author on 2017/12/29.
 */

public class CheckDialog {
    public static void initNetState(final Context context) {
        //初始化检测网络设置
        boolean networkAvailable = NetworkStateUtil.isNetWorkAvailable(context);
        if (!networkAvailable) {
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage("无网络连接,是否设置网络");
            builder.setTitle("温馨提示");
            builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    DeviceUtil.startWirelessSetting(context);
                }
            }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.create().show();
        }
    }

    public static void checkNotifation(final Activity context, final SuccessCallBack successCallBack) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage("不开启通知可以会错过很多重要信息哦");
        builder.setTitle("尚未开启通知");
        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                RequestPermissionUtil.jumpToSetNotication(context);
            }
        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                successCallBack.successcallback();
                dialog.dismiss();

            }
        });
        SharedPreferenceUtil.putBoolean(context, Constant.NOTIFATION, true);
        builder.create().show();
    }



    public static void showContactNotifation(final Activity context, String text) {
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage(text);
        builder.setTitle("复制成功");
        builder.setCancelable(false);
        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
        builder.create().show();
    }
}
